[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
basedir=/usr
bind-address={{ api_interface_address }}
port={{ server_port }}
socket=/var/lib/mysql{{ server_port }}/mysql.sock

log-error=/var/log/mariadb{{ server_port }}/mariadb.log

log-bin=mysql-bin
binlog_format=ROW
expire_logs_days=14
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_file_per_table=on
innodb_log_file_size = 256M

collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

datadir=/var/lib/mysql{{ server_port }}/

wsrep_cluster_address=gcomm://{% if (groups[galera_group_name|default('pri_mariadb')] | length) > 1 %}{% for host in groups[galera_group_name|default('pri_mariadb')] %}{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ wsrep_port }}{% if not loop.last %},{% endif %}{% endfor %}{% endif %}

wsrep_provider_options=gmcast.listen_addr=tcp://{{ api_interface_address }}:{{ wsrep_port }};ist.recv_addr={{ api_interface_address }}:{{ ist_port }}

#wsrep_provider_options="gcache.size=1024m;gcache.page_size=1024m;base_port={{ ist_port }}"

wsrep_node_address={{ api_interface_address }}:{{ wsrep_port }}
wsrep_sst_receive_address={{ api_interface_address }}:{{ sst_port }}

wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name="{{ cmp_galera_cluster_name }}"
wsrep_node_name={{ ansible_hostname }}
wsrep_sst_method={{ wsrep_sst_method }}
wsrep_sst_auth={{ cmp_galera_sst_user }}:{{ cmp_galera_sst_password }}
wsrep_slave_threads=4
wsrep_on = ON

max_connections=10000

key_buffer_size = '64M'
max_heap_table_size = '64M'
tmp_table_size = '64M'
{% set dynamic_pool_size_mb = (hostvars[inventory_hostname]['ansible_memtotal_mb'] * 0.4) | round | int %}
{% if dynamic_pool_size_mb < 8192 %}
innodb_buffer_pool_size = '{{ dynamic_pool_size_mb }}M'
{% else %}
innodb_buffer_pool_size = '8192M'
{% endif %}
log_bin_trust_function_creators = 1
innodb_lock_schedule_algorithm = FCFS

event_scheduler = ON
lower_case_table_names = 1  

max_allowed_packet = 512M

sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER

[server]
pid-file=/var/lib/mysql{{ server_port }}/mariadb.pid
